home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Think Class Libraries / CSICNPane 1.0 / TrackMouseClick / TrackMouseClick.c next >
Encoding:
C/C++ Source or Header  |  1994-11-30  |  1.9 KB  |  87 lines  |  [TEXT/KAHL]

  1. /******************************************************************************
  2.  TrackMouseClick.c
  3.  
  4.     BROWN UNIVERSITY AND ANDREW JAMES GILMARTIN GIVE NO WARRANTY, EITHER
  5.     EXPRESS OR IMPLIED, FOR THE PROGRAM AND/OR DOCUMENTATION PROVIDED,
  6.     INCLUDING, WITHOUT LIMITATION, WARRANTY OF MERCHANTABILITY AND
  7.     WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE.
  8.  
  9.     AUTHOR: Andrew_Gilmartin@Brown.Edu
  10.     MODIFIED: 93-04-14
  11.  
  12. ******************************************************************************/
  13.  
  14. #include "TrackMouseClick.h"
  15.  
  16.  
  17.  
  18. /******************************************************************************
  19.  TrackMouseClick
  20.  
  21.     A utilitiy routine to track the mouse within a rect. I the mouse is in
  22.     the rect then the rect is inverted. If flash is true when the user
  23.     mouse ups in the rect the rect is inverted MenuFlash times.
  24. ******************************************************************************/
  25.  
  26. Boolean TrackMouseClick( Rect* rect, Boolean flash )
  27. {
  28.     Point where;
  29.     short i;
  30.     long finalTick;
  31.     Boolean inverted;
  32.     
  33.         /* NOTE: TCL users should first "LongToQDRect( &frame, &rect );" */
  34.     
  35.     InsetRect( rect, 1, 1 );
  36.  
  37.         /* Track mouse and invert rect as needed */
  38.         
  39.     inverted = FALSE;
  40.     
  41.     do
  42.     {
  43.         GetMouse( &where );
  44.         
  45.         if ( PtInRect( where, rect ) )
  46.         {
  47.             if ( ! inverted )
  48.             {
  49.                 InvertRect( rect );
  50.                 inverted = TRUE;
  51.             }
  52.         }
  53.         else
  54.         {
  55.             if ( inverted )
  56.             {
  57.                 InvertRect( rect );
  58.                 inverted = FALSE;
  59.             }
  60.         }
  61.  
  62.     } while ( Button() );
  63.  
  64.         /* Did user mouse up outside of rect? */
  65.         
  66.     if ( ! inverted )
  67.         return FALSE;
  68.         
  69.         /* Otherwise, flash rect */
  70.         
  71.     SetHiliteMode(); /* invert with user's hilite color */
  72.     InvertRect( rect ); /* off */
  73.  
  74.     if ( flash )
  75.         for ( i = MenuFlash; i > 0; i-- )
  76.         {
  77.             Delay( 4, &finalTick );
  78.             SetHiliteMode();
  79.             InvertRect( rect ); /* on */
  80.             Delay( 4, &finalTick );
  81.             SetHiliteMode();
  82.             InvertRect( rect ); /* off */
  83.         }
  84.  
  85.     return TRUE;
  86.     
  87. } /* TrackMouseClick */